package reflect;

import reflect.annotation.AutoRunClass;

import java.io.File;
import java.net.URISyntaxException;

public class Test7 {
    public static void main(String[] args) throws URISyntaxException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        File dir=new File(
                Test7.class.getResource(".").toURI()
        );
        String packName=Test7.class.getPackage().getName();
       File[] files= dir.listFiles(f->f.getName().endsWith(".class"));
       for (File sub:files){
           String fileName=sub.getName();
           String className=fileName.substring(0,fileName.indexOf("."));
           Class cls=Class.forName(packName+"."+className);
           if (cls.isAnnotationPresent(AutoRunClass.class)) {
               Object obj=cls.newInstance();
               System.out.println(obj);
           }
       }
    }
}
